import request from '@/utils/request'

export const login = data => request.post('/sys/login', data)

export const getinfo = () => request.get('/sys/profile')

export const updatePass = data => request.put('/sys/user/updatePass', data)

export const department = () => request.get('/company/department')

export const simple = () => request.get('/sys/user/simple')

export const departmentpost = data => request.post('/company/department', data)

export const departmentpostid = id => request.get(`/company/department/${id}`)

export const getDepartmentDetail = (id, data) => request.put(`/company/department/${id}`, data)

export const del = id => request.delete(`/company/department/${id}`)

// export const role = params => request.get('/sys/role', { params })

export const getRoles = params => request.get('/sys/role', { params })

export const getRolesdata = data => request.post('/sys/role', data)

// /sys/role/{id}
export const upRole = data => request.put(`/sys/role/${data.id}`, data)

export const delllx = id => request.delete(`/sys/role/${id}`)

export const sysuser = params => request.get(`/sys/user`, { params })

export function expor() {
  return request({
    url: '/sys/user/export',
    // 改变接收数据的类型
    responseType: 'blob' // 使用blob接收二进制文件流
  })
}

export function getExportTemplate() {
  return request({
    url: '/sys/user/import/template',
    responseType: 'blob' // 二进制文件流
  })
}

export function uploadExcel(data) {
  return request({
    url: '/sys/user/import',
    method: 'post',
    data // form-data类型 因为要上传文件类型
  })
}

export function addEmployee(data) {
  return request({
    url: '/sys/user',
    method: 'post',
    data
  })
}

/**
 *  获取员工详情
 * **/

export function getEmployeeDetail(id) {
  return request({
    url: `/sys/user/${id}`
  })
}

export function updateEmployee(data) {
  return request({
    url: `/sys/user/${data.id}`,
    method: 'put',
    data
  })
}

export function getPermissionList() {
  return request({
    url: '/sys/permission'
  })
}

export function addPermission(data) {
  return request({
    url: '/sys/permission',
    method: 'post',
    data
  })
}

export function delPermission(id) {
  return request({
    url: `/sys/permission/${id}`,
    method: 'delete'
  })
}
export function getPermissionDetail(id) {
  return request({
    url: `/sys/permission/${id}`
  })
}

export function updatePermission(data) {
  return request({
    url: `/sys/permission/${data.id}`,
    method: 'put',
    data
  })
}

export const enabled = () => request.get(`/sys/role/list/enabled`)

export const enabledid = id => request.get(`/sys/user/${id}`)

export const assignRoles = data => request.put(`/sys/user/assignRoles`, data)
// sys / permission / { id }

export function getRoleDetail(id) {
  return request({
    url: `/sys/role/${id}`
  })
}

export function assignPerm(data) {
  return request({
    url: '/sys/role/assignPrem',
    method: 'put',
    data
  })
}
